//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package ciicos.controller;

import ciicos.base.ActionResult;
import ciicos.base.controller.SuperController;
import ciicos.base.vo.ListVO;
import ciicos.base.vo.PageListVO;
import ciicos.base.vo.PaginationVO;
import ciicos.constant.MsgCode;
import ciicos.engine.model.flowengine.FlowPagination;
import ciicos.entity.AppDataEntity;
import ciicos.model.AppDataCrForm;
import ciicos.model.AppDataListAllVO;
import ciicos.model.AppDataListVO;
import ciicos.model.AppFlowListAllVO;
import ciicos.service.AppDataService;
import ciicos.util.JsonUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import java.util.List;
import javax.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@Api(
        tags = {"app常用数据"},
        value = "data"
)
@RestController
@RequestMapping({"/api/app/Data"})
public class AppDataController extends SuperController<AppDataService, AppDataEntity> {
    @Autowired
    private AppDataService appDataService;

    @ApiOperation("常用数据")
    @GetMapping
    @ApiImplicitParams({@ApiImplicitParam(
            name = "type",
            value = "类型"
    )})
    public ActionResult<ListVO<AppDataListVO>> list(@RequestParam("type") String type) {
        List<AppDataEntity> list = this.appDataService.getList(type);
        List<AppDataListVO> data = JsonUtil.getJsonToList(list, AppDataListVO.class);
        ListVO listVO = new ListVO();
        listVO.setList(data);
        return ActionResult.success(listVO);
    }

    @PostMapping
    @ApiOperation("新建")
    @ApiImplicitParams({@ApiImplicitParam(
            name = "appDataCrForm",
            value = "常用模型",
            required = true
    )})
    public ActionResult create(@RequestBody @Valid AppDataCrForm appDataCrForm) {
        AppDataEntity entity = (AppDataEntity)JsonUtil.getJsonToBean(appDataCrForm, AppDataEntity.class);
        if (this.appDataService.isExistByObjectId(entity.getObjectId(), appDataCrForm.getSystemId())) {
            return ActionResult.fail("常用数据已存在");
        } else {
            this.appDataService.create(entity);
            return ActionResult.success(MsgCode.SU001.get());
        }
    }

    @ApiOperation("删除")
    @DeleteMapping({"/{objectId}"})
    @ApiImplicitParams({@ApiImplicitParam(
            name = "objectId",
            value = "主键",
            required = true
    )})
    public ActionResult create(@PathVariable("objectId") String objectId) {
        AppDataEntity entity = this.appDataService.getInfo(objectId);
        if (entity != null) {
            this.appDataService.delete(entity);
            return ActionResult.success(MsgCode.SU003.get());
        } else {
            return ActionResult.fail(MsgCode.FA003.get());
        }
    }

    @ApiOperation("所有流程")
    @GetMapping({"/getFlowList"})
    public ActionResult<PageListVO<AppFlowListAllVO>> getFlowList(FlowPagination pagination) {
        List<AppFlowListAllVO> list = this.appDataService.getFlowList(pagination);
        PaginationVO paginationVO = (PaginationVO)JsonUtil.getJsonToBean(pagination, PaginationVO.class);
        return ActionResult.page(list, paginationVO);
    }

    @ApiOperation("所有应用")
    @GetMapping({"/getDataList"})
    public ActionResult<ListVO<AppDataListAllVO>> getAllList() {
        List<AppDataListAllVO> result = this.appDataService.getDataList("2");
        ListVO listVO = new ListVO();
        listVO.setList(result);
        return ActionResult.success(listVO);
    }
}
